/**
 * Copyright © 2021-2025 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.invoice.qrcode.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.invoice.qrcode.service.dto.YxfpQrcodeDTO;
import com.jeeplus.invoice.qrcode.domain.YxfpQrcode;
import com.jeeplus.invoice.qrcode.mapper.YxfpQrcodeMapper;

/**
 * 二维码管理Service
 * @author 张如利
 * @version 2022-01-20
 */
@Service
@Transactional
public class YxfpQrcodeService extends ServiceImpl<YxfpQrcodeMapper, YxfpQrcode> {

	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	public YxfpQrcodeDTO findById(String id) {
		return baseMapper.findById(id);
	}

	/**
	 * 根据商户id查询
	 * @param merchantId
	 * @return
	 */
	public YxfpQrcodeDTO findByMerchantId(String merchantId) {
		return baseMapper.findByMerchantId(merchantId);
	}

	/**
	 * 自定义分页检索
	 * @param page
	 * @param queryWrapper
	 * @return
	 */
	public IPage <YxfpQrcodeDTO> findPage(Page <YxfpQrcodeDTO> page, QueryWrapper queryWrapper) {
		queryWrapper.eq ("a.del_flag", 0 ); // 排除已经删除
		return  baseMapper.findList(page, queryWrapper);
	}

	/**
	 * 商家绑定二维码
	 * @param merchantId
	 * @param qrcodeId
	 */
	public void bindingQrcode(String merchantId,String qrcodeId){
		baseMapper.bindingQrcode(merchantId,qrcodeId);
	}

	/**
	 * 商家解除绑定二维码
	 * @param qrcodeId
	 */
	public void unBindingQrcode(String qrcodeId){
		baseMapper.unBindingQrcode(qrcodeId);
	}

	/**
	 * 根据二维码内容查询商户ID
	 * @param content 二维码内容
	 */
	public YxfpQrcodeDTO getMerchantIdByContent(String content){
		return baseMapper.getMerchantIdByContent(content);
	}

}
